#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2022-11-2 21:56
import csv

import shortuuid as shortuuid
from faker import Faker

from lingzhu.tools.write_to_csv import write_to_csv
from xhqb.mock_name import random_name


def make_register_data():
    fake = Faker(locale='zh_CN')
    register_data_list = []
    data_name = 'Tina-' + shortuuid.ShortUUID(alphabet='1234567890').random(6)
    phone = fake.phone_number()
    password = '12369'
    name = random_name()
    identity_no = fake.ssn()
    app_channel = 'huawei01'
    device_id = '00310000000211109104931unknown00000000000000000000000000+BJGj9U='
    gps_address = ''
    gps_area = ''
    gps_city = ''
    gps_province = ''
    latitude = ''
    longitude = ''
    register_data_list.append(data_name)
    register_data_list.append(phone)
    register_data_list.append(password)
    register_data_list.append(name)
    register_data_list.append(identity_no)
    register_data_list.append(app_channel)
    register_data_list.append(device_id)
    register_data_list.append(gps_address)
    register_data_list.append(gps_area)
    register_data_list.append(gps_city)
    register_data_list.append(gps_province)
    register_data_list.append(latitude)
    register_data_list.append(longitude)

    return register_data_list


# 将测试数据放入列表
def data_to_csv(num, file_name, batch_num):
    # base_list = []
    #    counter = 0
    time = 1
    base_data_list = []
    for i in range(1, batch_num + 1):
        fake_new_list = make_register_data()
        base_data_list.append(fake_new_list)
        if i % batch_num == 0:
            write_to_csv(file_name, base_data_list)
            print(f'第{time}次写入！')
            base_data_list = []
            time += 1


#       base_list.append(fake_new_list)
#   return base_list


if __name__ == '__main__':
    file_name = 'test.csv'
    headers = ['数据集名称', '$dc{phone}', '$dc{password}', '$dc{name}', '$dc{identity_no}', '$dc{appChannel}',
               '$dc{deviceID}', '$dc{gpsAddress}', '$dc{gpsArea}', '$dc{gpsCity}', '$dc{gpsProvince}', '$dc{latitude}',
               '$dc{longitude}']
    with open(file_name, 'w', encoding='UTF8', newline='') as f:
        writer_header = csv.writer(f)
        writer_header.writerow(headers)

    data_to_csv(200000, file_name, 1000)
    print('执行完毕')

# data = ['Tina的数据1', '19100000034', '12369', '', '', 'huawei01',
#         '00310000000211109104931unknown00000000000000000000000000+BJGj9U=', '', '', '', '', '', '']
